env = ENV['RAILS_ENV'] || 'development' 
database = "albumx_#{env}"
user = "abmxuser_#{env[0..0]}"

def connect
	ActiveRecord::Base.establish_connection(
	:adapter => 'jdbc', 
	:driver => 'com.mysql.jdbc.Driver', 
	:username => 'root',
	:password => 'ror',
	:url => 'jdbc:mysql://localhost/mysql' 
	)
end

task :db_setup => :environment do
	ActiveRecord::Schema.define do
	connect
	begin
		create_database database
		rescue
	end
	execute "create user #{user}@localhost identified by 'ror'"
	execute "grant all privileges on #{database}.* to '#{user}'@'localhost'" 
	end 
end

task :db_clean => :environment do
	ActiveRecord::Schema.define do
	connect
	begin
		execute "drop user '#{user}'@'localhost'"
		rescue
	end
	drop_database database
	end
end